/**
 * edge To labels
 * @param { string }  text  文字
 * @param { number }  fontSize  字体
 */
export const edgeLabels = (text: string, fontSize: number = 10) => {
  const labels = [
    {
      markup: [
        {
          tagName: "text",
          selector: "txt",
        },
      ],
      attrs: {
        body: {
          fill: "#2A82E4",
          stroke: "#17559C",
        },
        txt: {
          text,
          textAnchor: "middle",
          textVerticalAnchor: "middle",
          refX: 0,
          refY: -10,
          fill: "#fff",
          fontSize,
        },
      },
    },
  ];
  return labels;
};
/**
 * edge To attrs
 * @param { number }  size  线的大小
 * @param { number }  lineMode 单线or双线
 */
export const edgeAttrs = (size: number = 2, lineMode?: number) => {
  const edgeAttr = {
    line: {
      stroke: "#2A82E4",
      strokeWidth: 1,
      sourceMarker: {
        name: lineMode === 2 && "block",
        size,
      },
      targetMarker: {
        name: "block",
        size,
      },
    },
  };
  return edgeAttr;
};

/**
 * edge To router
 * @param { string }  name router类型
 */
type TypeColor = string[];
const edgeTypeLine: TypeColor = ["normal", "er", "manhattan"];
export const edgeRouter = (edgeType: number = 1) => {
  const routers = {
    name: edgeTypeLine[Number(edgeType - 1)],
    args: {
      offset: "center",
    },
  };
  return routers;
};
